class MyPage extends BaseList {
    constructor(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl) {
        super(action, orderby, flag, $pagesize, $pagination, cokiePageSize, cokiePageIndex, cokieListResult, listUrl, delUrl);
        this.showloadingwnd = true;
    }
    OnPageLoad() {
        // 回车直接进行搜索
        $("panel_search").bind('keyup', function (e) {
            let key = e.keyCode;
            if (key === 13) {
                _Instance.FetchForPage(1);
            }
        });
        $('#loading').hide();
    }
    SetCriterion(item) {
        item['End'] = $.trim($("#End").val()) === '' ? null : $.trim($("#End").val());
        item['SupplierName'] = $.trim($("#SupplierNameFilterValue").val());
        //item['OrderBy'] = _order_by;
        return item;
    }
    GetFilter() {
        let item = super.GetFilter(0);
        // 设置条件
        item = this.SetCriterion(item);
        return JSON.stringify(item);
    }
    EmptyTableContent() {
        $("#tab_data01 tbody").empty();
    }
    SetTableContent(result) {
        $("#tab_data01 tbody").empty();

        let content_01 = '';
        this.rows = 0;
        for (let i = 0; i < result.length; i++) {
            if (result[i].rowFlag === 1) {
                content_01 += '<tr>';
                content_01 += '<td style="text-overflow:ellipsis;" title="' + result[i].stockInBillNo + '">' + formatNullData(result[i].stockInBillNo) + '</td>';
                content_01 += '<td style="text-overflow:ellipsis;" title="' + result[i].styleNo + '">' + formatNullData(result[i].styleNo) + '</td>';
                content_01 += '<td>' + formatNullData(result[i].supplierName) + '</td>';
                content_01 += '<td>' + formatNullData(result[i].mrpQuantity) + '</td>';
                content_01 += '<td>' + formatNullData(result[i].stockInQuantity) + '</td>';
                content_01 += '<td>' + formatNullData(result[i].shortRuleQuantity) + '</td>';
                content_01 += '<td>' + formatNullData(result[i].orderArrivalDate) + '</td>';
                content_01 += '<td>' + formatNullData(result[i].stockInDate) + '</td>';
                content_01 += '<td>' + formatNullData(result[i].materialName) + '</td>';
                content_01 += '<td>' + formatNullData(result[i].materialCode) + '</td>';
                content_01 += '<td>' + formatNullData(result[i].materialColourName) + '</td>';
                content_01 += '<td>' + formatNullData(result[i].specification) + '</td>';
                content_01 += '<td>' + formatNullData(result[i].destination) + '</td>';
                content_01 += '</tr>';
                this.rows += 1;
            }
            if (result[i].rowFlag === 2 && $("#SubTotalFlag").is(":checked")) {
                content_01 += '<tr style="background-color:#ffe4b5; color:#000;">';
                content_01 += '<td colspan="4" style="text-align:right; padding-right:20px; font-weight:bold;">（小 计）</td>';
                content_01 += '<td>' + formatNullData(result[i].stockInQuantity) + '</td>';
                content_01 += '<td colspan="8"></td>';
                content_01 += '</tr>';
                this.rows += 1;
            }
            $("#tab_data01 tbody").append(content_01);
            content_01 = '';
        }
        setOneTableRowColor("tab_data01");

        this.AutoAdjustTableHeightForLines();   // 自适应高度设置
        $(window).resize();                     // 防止因为出现滚动条而造成画面显示问题
        $('#loading').hide();
    }
    //《按钮》搜索
    DoSearch() {
        if (formatNullInputValue($.trim($("#SupplierNameFilterValue").val())) === null) {
            ShowErrorMessagePanel('供应商检索条件不能空。');
            return false;
        } else {
            this.FetchForPage(1);
        }
    }
    ShowSubTotal() {
        if (this.pageData !== null) {
            this.SetTableContent(this.pageData);
        } else {
            return false;
        }
    }
    AutoAdjustTableHeightForLines() {
        let h = $(window).height();
        let _rc = Math.floor((h - 147 - 25) / 25);
        let _dh = _rc * 25;
        let _tah = this.rows * 25;
        _dh = (_tah >= _dh) ? _dh : _tah;

        $("#div_content").css({"max-height": _dh, height: _dh});
    }
}

var _Instance = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    $("#search_btn").hide(); // 无需搜索，隐藏搜索按钮
    _Instance = new MyPage(0, null, null, null, null, null, null, null,
            "/purchase/report/open_notes_payabled/fetchAll.html",
            "");

    window.laydate.render({
        elem: '#End',
        theme: '#393D49',
        trigger: 'click'
    });

    _Instance.OnPageLoad();
}

// 画面大小或者位置移动
function onPageResize() {
    if (_Instance !== null)
        _Instance.AutoAdjustTableHeightForLines();
}
